﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MQ.Core.Common;
using MQ.Core.Entity.System;
using MQ.Core.IService.System;

namespace MQ.Core.Admin.Areas.System.Controllers
{
    /// <summary>
    /// 公司
    /// </summary>
    [Route("api/system/[controller]")]
    public class CompanyController : ApiController
    {
        private readonly ICompanyService companyService;
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="companyService"></param>
        public CompanyController(ICompanyService companyService)
        {
            this.companyService = companyService;
        }
        /// <summary>
        /// fenye
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("page")]
        public object GetPageList([FromQuery]Pagination pagination, [FromQuery]string query)
        {
            var data = companyService.GetPageList(pagination, query);
            return Success(pagination, data);
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("list")]
        public object GetList([FromForm]string query)
        {
            var data = companyService.GetList(query);
            return Success(data);
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("save")]
        public object Save([FromForm]CompanyEntity entity)
        {
            companyService.Save(entity);
            return Success();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("delete")]
        public object Delete([FromForm]string ids)
        {
            companyService.Delete(ids);
            return Success();
        }
    }
}